﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Data;
using AdminModule.IndexMarkServiceReference;
using SharedCode;

namespace AdminModule.ViewModels
{
    public class ViewDataVM : ViewModelBase
    {
        public IndexMarkServiceClient client = new IndexMarkServiceClient();

        public ViewDataVM()
        {
            client.GetAdmCategoriesByTermCompleted += new EventHandler<GetAdmCategoriesByTermCompletedEventArgs>(client_GetAdmCategoriesByTermCompleted);
            client.GetAdmPositionsCompleted += new EventHandler<GetAdmPositionsCompletedEventArgs>(client_GetAdmPositionsCompleted);
            client.GetAdmStatusesCompleted += new EventHandler<GetAdmStatusesCompletedEventArgs>(client_GetAdmStatusesCompleted);
            client.GetGradationsStructCompleted += new EventHandler<GetGradationsStructCompletedEventArgs>(client_GetGradationsStructCompleted);
            client.GetAdmJobsCompleted += new EventHandler<GetAdmJobsCompletedEventArgs>(client_GetAdmJobsCompleted);
            client.GetAdmPersonsCompleted += new EventHandler<GetAdmPersonsCompletedEventArgs>(client_GetAdmPersonsCompleted);
            client.GetAdmTermsCompleted += new EventHandler<GetAdmTermsCompletedEventArgs>(client_GetAdmTermsCompleted);
            client.GetAdmUnitsCompleted += new EventHandler<GetAdmUnitsCompletedEventArgs>(client_GetAdmUnitsCompleted);
            client.GetAdmResponsiblesCompleted += new EventHandler<GetAdmResponsiblesCompletedEventArgs>(client_GetAdmResponsiblesCompleted);
        }

        #region Ответственные
        private ObservableCollection<AdmResponsible> responsibles = new ObservableCollection<AdmResponsible>();
        public ObservableCollection<AdmResponsible> AdmResponsibleCollection
        {
            get
            {
                return this.responsibles;
            }
            set
            {
                this.responsibles = value;
            }
        }

        void client_GetAdmResponsiblesCompleted(object sender, GetAdmResponsiblesCompletedEventArgs e)
        {
            responsibles.Clear();
            foreach (var s in e.Result)
            {
                responsibles.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmResponsible));
        }

        public void LoadAdmResponsible(int IDTerm)
        {
            client.GetAdmResponsiblesAsync(IDTerm);
        }
        #endregion

        #region Категории
        private ObservableCollection<AdmCategory> categories = new ObservableCollection<AdmCategory>();
        public ObservableCollection<AdmCategory> AdmCategoryCollection
        {
            get
            {
                return this.categories;
            }
            set
            {
                this.categories = value;
            }
        }

        void client_GetAdmCategoriesByTermCompleted(object sender, GetAdmCategoriesByTermCompletedEventArgs e)
        {
            categories.Clear();
            foreach (var s in e.Result)
            {
                categories.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmCategory));
        }

        public void LoadAdmCategory(int IDTerm)
        {
            client.GetAdmCategoriesByTermAsync(IDTerm);
        }
        #endregion

        #region Должности
        private ObservableCollection<AdmPosition> positions = new ObservableCollection<AdmPosition>();
        public ObservableCollection<AdmPosition> AdmPositionCollection
        {
            get
            {
                return this.positions;
            }
            set
            {
                this.positions = value;
            }
        }

        void client_GetAdmPositionsCompleted(object sender, GetAdmPositionsCompletedEventArgs e)
        {
            positions.Clear();
            foreach (var s in e.Result)
            {
                positions.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmPosition));
        }

        public void LoadAdmPosition()
        {
            client.GetAdmPositionsAsync();
        }
        #endregion

        #region Ставки
        private ObservableCollection<AdmStatus> statuses = new ObservableCollection<AdmStatus>();
        public ObservableCollection<AdmStatus> AdmStatusCollection
        {
            get
            {
                return this.statuses;
            }
            set
            {
                this.statuses = value;
            }
        }

        void client_GetAdmStatusesCompleted(object sender, GetAdmStatusesCompletedEventArgs e)
        {
            statuses.Clear();
            foreach (var s in e.Result)
            {
                statuses.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmStatus));
        }

        public void LoadAdmStatus()
        {
            client.GetAdmStatusesAsync();
        }
        #endregion

        #region Работа
        private ObservableCollection<AdmJob> jobs = new ObservableCollection<AdmJob>();
        public ObservableCollection<AdmJob> AdmJobCollection
        {
            get
            {
                return this.jobs;
            }
            set
            {
                this.jobs = value;
            }
        }

        void client_GetAdmJobsCompleted(object sender, GetAdmJobsCompletedEventArgs e)
        {
            jobs.Clear();
            foreach (var s in e.Result)
            {
                jobs.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmJob));
        }

        public void LoadAdmJob()
        {
            client.GetAdmJobsAsync();
        }
        #endregion

        #region Сотрудники
        private ObservableCollection<AdmPerson> persons = new ObservableCollection<AdmPerson>();
        public ObservableCollection<AdmPerson> AdmPersonCollection
        {
            get
            {
                return this.persons;
            }
            set
            {
                this.persons = value;
            }
        }

        void client_GetAdmPersonsCompleted(object sender, GetAdmPersonsCompletedEventArgs e)
        {
            persons.Clear();
            foreach (var s in e.Result)
            {
                persons.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmPerson));
        }

        public void LoadAdmPerson()
        {
            client.GetAdmPersonsAsync();
        }
        #endregion

        #region Периоды
        private ObservableCollection<AdmTerm> terms = new ObservableCollection<AdmTerm>();
        public ObservableCollection<AdmTerm> AdmTermCollection
        {
            get
            {
                return this.terms;
            }
            set
            {
                this.terms = value;
            }
        }

        void client_GetAdmTermsCompleted(object sender, GetAdmTermsCompletedEventArgs e)
        {
            terms.Clear();
            foreach (var s in e.Result)
            {
                terms.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmTerm));
        }

        public void LoadAdmTerm()
        {
            client.GetAdmTermsAsync();
        }
        #endregion

        #region Единицы измерения
        private ObservableCollection<AdmUnit> units = new ObservableCollection<AdmUnit>();
        public ObservableCollection<AdmUnit> AdmUnitCollection
        {
            get
            {
                return this.units;
            }
            set
            {
                this.units = value;
            }
        }

        void client_GetAdmUnitsCompleted(object sender, GetAdmUnitsCompletedEventArgs e)
        {
            units.Clear();
            foreach (var s in e.Result)
            {
                units.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmUnit));
        }

        public void LoadAdmUnit()
        {
            client.GetAdmUnitsAsync();
        }
        #endregion

        #region Градации
        private ObservableCollection<AdmGradation> gradations = new ObservableCollection<AdmGradation>();
        public ObservableCollection<AdmGradation> AdmGradationCollection
        {
            get
            {
                return this.gradations;
            }
            set
            {
                this.gradations = value;
            }
        }

        void client_GetGradationsStructCompleted(object sender, GetGradationsStructCompletedEventArgs e)
        {
            gradations.Clear();
            foreach (var s in e.Result)
            {
                gradations.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmGradation));
        }

        public void LoadAdmGradation(int IDTerm)
        {
            client.GetGradationsStructAsync(IDTerm);
        }
        #endregion
    }
}
